1
2
3
4
5
6
7
8 package gov.noaa.eds.xapi.generic;
9
10 import gov.noaa.eds.xapi.generic.handlers.ResourceHandler;
11 import java.net.URL;
12 import junit.framework.*;
13 import org.w3c.dom.Document;
14 import org.w3c.dom.Node;
15 import org.xmldb.api.base.ErrorCodes;
16 import org.xmldb.api.base.XMLDBException;
17
18
19 /***
20 *
21 * @author tns
22 */
23 public class GenericDomHandlerResourceTest extends TestCase {
24
25 GenericDomHandlerResource resource = null;
26 URL resourceUrl = null;
27 String resourceId = "1";
28 String resourceString = "testXmlResource.xml";
29
30 public GenericDomHandlerResourceTest(String testName) {
31 super(testName);
32 }
33
34 protected void setUp() throws java.lang.Exception {
35 resource = new GenericDomHandlerResource();
36 ResourceHandler handler = new ResourceHandler();
37 handler.setResource(resourceString);
38 resource.setDomHandler(handler);
39 resource.setId(this.resourceId);
40 }
41
42 protected void tearDown() throws java.lang.Exception {
43 }
44
45 public static junit.framework.Test suite() {
46 junit.framework.TestSuite suite = new junit.framework.TestSuite(GenericDomHandlerResourceTest.class);
47
48 return suite;
49 }
50
51 /***
52 * Test of getDomHandler method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
53 */
54 public void testGetDomHandler() {
55 System.out.println("testGetDomHandler");
56
57
58 DomHandler h = resource.getDomHandler();
59 assertNotNull("expected a valid DomHandler",h);
60 }
61
62 /***
63 * Test of setDomHandler method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
64 */
65 public void testSetDomHandler() {
66 System.out.println("testSetDomHandler");
67
68
69 DomHandler h = new ResourceHandler();
70 resource.setDomHandler(h);
71 }
72
73 /***
74 * Test of getSAXFeature method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
75 */
76 public void testGetSAXFeature() throws Exception {
77 System.out.println("testGetSAXFeature");
78 try {
79 resource.getSAXFeature("");
80 fail("excpetion expected");
81 } catch (UnsupportedOperationException expected){
82
83 }
84
85 }
86
87 /***
88 * Test of setContentAsDOM method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
89 */
90 public void testSetContentAsDOM() throws Exception {
91 System.out.println("testSetContentAsDOM");
92
93
94 Document node = GenericResourceTest.loadTestResource();
95 try {
96 resource.setContentAsDOM(node);
97 fail("exception expected");
98 } catch (UnsupportedOperationException expected){
99
100 }
101 }
102
103 /***
104 * Test of getContentAsSAX method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
105 */
106 public void testGetContentAsSAX() throws Exception {
107 System.out.println("testGetContentAsSAX");
108 try {
109 resource.getContentAsSAX(null);
110 fail("excpetion expected");
111 } catch (XMLDBException expected){
112 assertEquals("expected not implemented",ErrorCodes.NOT_IMPLEMENTED,expected.errorCode);
113
114 }
115 }
116
117 /***
118 * Test of setSAXFeature method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
119 */
120 public void testSetSAXFeature() throws Exception {
121 System.out.println("testSetSAXFeature");
122
123 try {
124 resource.setSAXFeature("",false);
125 fail("excpetion expected");
126 } catch (UnsupportedOperationException expected){
127
128 }
129 }
130
131 /***
132 * Test of setContentAsSAX method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
133 */
134 public void testSetContentAsSAX() throws Exception {
135 System.out.println("testSetContentAsSAX");
136
137 try {
138 resource.setContentAsSAX();
139 fail("excpetion expected");
140 } catch (XMLDBException expected){
141 assertEquals("expected not implememented error code",ErrorCodes.NOT_IMPLEMENTED,expected.errorCode);
142
143 }
144 }
145
146 /***
147 * Test of getDocumentId method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
148 */
149 public void testGetDocumentId() throws Exception {
150 System.out.println("testGetDocumentId");
151
152
153 String id = resource.getDocumentId();
154 assertNotNull("Expected a valid id",id);
155 assertEquals("Unexpected id",resourceId,id);
156 }
157
158 /***
159 * Test of getContentAsDOM method, of class gov.noaa.eds.xapi.generic.GenericXmlResource.
160 */
161 public void testGetContentAsDOM() throws Exception {
162 System.out.println("testGetContentAsDOM");
163
164
165 Node node = resource.getContentAsDOM();
166 assertNotNull("expected a valid node",node);
167 assertEquals("expected a document root","#document",node.getNodeName());
168 }
169
170
171
172
173 }